package com.my.study.proxy;

import java.lang.reflect.Proxy;

/**
 * @author: yidujun
 * @create: 2021/07/12 10:24
 */
public class ProxyFactory<T> {

    private Class<T> methodInterface;

    public ProxyFactory(Class<T> methodInterface) {
        this.methodInterface = methodInterface;
    }

    @SuppressWarnings("unchecked")
    protected T newInstance(RealMethodProxy proxy) {
        return (T) Proxy.newProxyInstance(methodInterface.getClassLoader(), new Class[]{methodInterface}, proxy);
    }

    public T newInstance(RealInvokeMethod realInvokeMethod) {
        RealMethodProxy proxy = new RealMethodProxy(realInvokeMethod);
        return newInstance(proxy);
    }

}
